<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    function get(options){
        var { url, data = "", async = true, dataType = "text", success } = options;

        if(data instanceof Object){
            var list = [];
            for(var key in data){
                var val = data[key];
                var item = key + "=" + val;
                list.push(item);
            }

            var data = list.join("&");
        }

        var xhr = new XMLHttpRequest();

        xhr.open("get", data? url + "?" + data : url, async);

        xhr.send();

        xhr.onreadystatechange = function(){
            if(xhr.readyState == 4 && xhr.status ==200){
                var result = xhr.responseText;
                if(dataType == "json"){
                    result = JSON.parse(result);
                }

                if(success){
                    success(result);
                }
            }
        }
    }
</script>
</html>